﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.Mobile.ContainerModel;
using System.Mobile.Mvc;
using MultiPanelTest.Login;
using MultiPanelTest.Search;
using System.Drawing;

namespace MultiPanelTest
{
    public class ApplicationManager
    {
        private static Container container;

        static ApplicationManager()
        {
            Initialize();
        }


        public static Container Container
        {
            get
            {
                return container;
            }
        }

        private static void Initialize()
        {
            container = new Container();

            // Register Login view and controller
            container.Register<LoginView>(c => new LoginView());
            container.Register<LoginController>(c => new LoginController(c.Resolve<LoginView>()))
                .InitializedBy((c, v) => v.Container = c);

            // Register Search view and controller
            container.Register<SearchView>(c => new SearchView());
            container.Register<SearchController>(c => new SearchController(c.Resolve<SearchView>()))
                .InitializedBy((c, v) => v.Container = c);

            //// Register Search view and controller
            //container.Register<DetailForm>(c => new DetailForm());
            //container.Register<DetailController>(c => new DetailController(c.Resolve<DetailForm>()))
            //    .InitializedBy((c, v) => v.Container = c);

            container.Register<Products>(c => new Products());          

            // Set ControllerProvider
            Navigator.SetControllerProvider( new ControllerProvider(container));         
           
        }

        public static void InitializeViews(Form form)
        {           

            LoginController loginController = container.Resolve<LoginController>();
            loginController.Initialize();           
            Control view = loginController.View as Control;
            view.Size = new Size(240, 250);
            form.Controls.Add(view);
            view.Hide();

            SearchController searchController = container.Resolve<SearchController>();           
            Control searchView = searchController.View as Control;
            searchView.Size = new Size(240, 250);
            form.Controls.Add(searchView);
            searchView.Hide();

        }

        // Application entry point
        public static void Start()
        {
            MainForm form = new MainForm();
            //InitializeViews(form);
            Application.Run(form);
        }
    }
}
